package com.dearbinge.data.service.impl.defrayStream;

import com.baomidou.mybatisplus.plugins.Page;
import com.dearbinge.data.api.defrayStream.DefrayStreamService;
import com.dearbinge.data.dao.DefrayStreamMapper;
import com.dearbinge.data.pojo.defrayStream.DefrayStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "defrayStreamService")
public class DefrayStreamServiceImpl implements DefrayStreamService {

    @Autowired
    private DefrayStreamMapper defrayStreamMapper;

    @Override
    public Integer update(DefrayStream defrayStream) {
        Integer dataCode= defrayStreamMapper.update(defrayStream);
        return dataCode;
    }

    @Override
    public Integer insert(DefrayStream defrayStream) {
        Integer dataCode= defrayStreamMapper.insert(defrayStream);
        return dataCode;
    }

    @Override
    public Integer delete(Integer id) {
        Integer dataCode= defrayStreamMapper.delete(id);
        return dataCode;
    }

    @Override
    public Page getByUserIdPage(String userId, Integer pageNo, Integer pageSize) {
        pageNo = (null == pageNo || pageNo < 1) ? 1 : pageNo;
        pageSize = (null == pageSize || pageSize < 0) ? 1 :pageSize;
        Page<DefrayStream> page = new Page<DefrayStream>(pageNo, pageSize);
        List<DefrayStream> list = defrayStreamMapper.getByUserIdPage(userId, page);
        page.setRecords(list);
        Integer total = defrayStreamMapper.count(userId);
        page.setTotal(total);
        return page;
    }
}
